using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Serialization;
using Sirenix.Utilities;
using Pangoo.Common;
using System.Dynamic;





#if UNITY_EDITOR
using System.Reflection;
using UnityEditor;
#endif

namespace MetaTable
{

    [Serializable]
    public class MetaTableColumn
    {

        [TableTitleGroup("名字")]
        [HideLabel]
        [TableColumnWidth(60)]
        public string Name;

        [TableTitleGroup("类型")]
        [ValueDropdown("GetTypeList", AppendNextDrawer = true)]
        [HideLabel]
        [TableColumnWidth(90)]
        public string Type;



        [TableTitleGroup("中文名")]
        [HideLabel]
        [TableColumnWidth(60)]
        public string CnName;

        [TableTitleGroup("Edit")]
        [HideLabel]
        [TableColumnWidth(30, resizable: false)]
        public bool IsEditor;

        [TableTitleGroup("属性列表")]
        [ValueDropdown("OnAttributesValueDropdown")]
        [HideLabel]
        [TableColumnWidth(60)]
        public List<string> Attributes;

#if UNITY_EDITOR
        IEnumerable GetTypeList()
        {
            ValueDropdownList<string> ret = new ValueDropdownList<string>();
            ret.Add("string");
            ret.Add("list|string");
            ret.Add("uint");
            ret.Add("int");
            ret.Add("list|int");
            ret.Add("float");
            ret.Add("list|float");
            ret.Add("double");
            ret.Add("list|double");
            ret.Add("Vector3");
            ret.Add("list|Vector3");
            ret.Add("bool");
            ret.Add("list|bool");
            ret.Add("Color");

            var types = AssemblyUtility.GetTypes(typeof(MetaTableData));
            foreach (var type in types)
            {
                ret.Add(type.FullName);
                ret.Add("list|" + type.FullName);
            }

            return ret;
        }

        IEnumerable OnAttributesValueDropdown()
        {
            var ret = new ValueDropdownList<string>();
            ret.Add("ReadOnly");
            ret.Add("HideInInspector");
            var types = AssemblyUtility.GetTypes(typeof(MetaTableAttribute));
            foreach (var type in types)
            {
                if (!type.IsAbstract)
                {
                    var instance = Activator.CreateInstance(type) as MetaTableAttribute;
                    if (instance != null)
                    {
                        ret.Add(instance.Title, type.FullName);
                    }
                }
            }
            return ret;
        }

#endif
    }
}

